package com.tianruan.dc.modules.repo.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.tianruan.dc.common.utils.BeanMapper;
import com.tianruan.dc.modules.repo.dto.RepoDTO;
import com.tianruan.dc.modules.repo.dto.response.RepoRespDTO;
import com.tianruan.dc.modules.repo.entity.Repo;
import com.tianruan.dc.modules.repo.mapper.RepoMapper;
import com.tianruan.dc.modules.repo.service.RepoService;
import com.tianruan.dc.modules.sys.user.utils.PageBean;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

/**
* <p>
* 语言设置 服务实现类
* </p>
*
*/
@Service
public class RepoServiceImpl extends ServiceImpl<RepoMapper, Repo> implements RepoService {



    @Override
    public void save(RepoDTO reqDTO) {

        //复制参数
        Repo entity = new Repo();
        entity.setCreateTime(LocalDateTime.now());
        entity.setUpdateTime(LocalDateTime.now());
        BeanMapper.copy(reqDTO, entity);
        this.saveOrUpdate(entity);
    }

    @Override
    public PageBean<RepoRespDTO> PageRepo(Integer page, Integer pageSize, String title) {
        //创建pageBean对象
        PageBean<RepoRespDTO> pageBean = new PageBean<>();
        //开启分页查询  和 模糊查询
        PageHelper.startPage(page,pageSize);
        List<RepoRespDTO> pageInfo = baseMapper.pageRepo(page,pageSize,title);
        Page<RepoRespDTO> page1 = (Page<RepoRespDTO>) pageInfo;
        //把数据填充到pagebean对象中
        pageBean.setTotal((long) page1.size());
        pageBean.setItems(page1.getResult());
        //返回pagebean对象
        return pageBean;
    }
}
